package com.turnengine.client.global.translation.command;

import com.javabi.common.locale.LanguageCountry;
import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Get Translation By Id.
 */
public class GetTranslationById implements IGetTranslationById {

	/** The command id. */
	public static final short COMMAND_ID = 403;

	/** The id. */
	private int id;
	/** The language. */
	private LanguageCountry language;

	/**
	 * Creates a new Get Translation By Id.
	 */
	public GetTranslationById() {
	}

	/**
	 * Creates a new Get Translation By Id.
	 * @param id the id
	 * @param language the language
	 */
	public GetTranslationById(int id, LanguageCountry language) {
		setId(id);
		setLanguage(language);
	}

	/**
	 * Creates a new Get Translation By Id.
	 * @param iGetTranslationById the i get translation by id
	 */
	public GetTranslationById(IGetTranslationById iGetTranslationById) {
		setId(iGetTranslationById.getId());
		setLanguage(iGetTranslationById.getLanguage());
	}

	/**
	 * Returns the id.
	 * @return the id.
	 */
	public int getId() {
		return id;
	}

	/**
	 * Returns the language.
	 * @return the language.
	 */
	public LanguageCountry getLanguage() {
		return language;
	}

	/**
	 * Sets the id.
	 * @param id the id to set.
	 */
	public void setId(int id) {
		this.id = id;
	}

	/**
	 * Sets the language.
	 * @param language the language to set.
	 */
	public void setLanguage(LanguageCountry language) {
		if (language == null) {
			throw new NullPointerException("language");
		}
		this.language = language;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(199, 37);
		hash.append(id);
		hash.append(language);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof GetTranslationById) {
			GetTranslationById compare = (GetTranslationById) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.id, compare.id);
			equals.append(this.language, compare.language);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(IGetTranslationById compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.id, compare.getId());
		builder.append(this.language, compare.getLanguage());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		string.append("id", id);
		if (language != null) {
			string.append("language", language);
		}
		return string.toString();
	}

	public short getCommandId() {
		return COMMAND_ID;
	}
}
